<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <title class="lift:Menu.title">App: </title>
    <style class="lift:CSS.blueprint"></style>
    <style class="lift:CSS.fancyType"></style>
    <script id="jquery" src="/classpath/jquery.js" type="text/javascript"></script>
    <script id="json" src="/classpath/json.js" type="text/javascript"></script>

    <style Type="text/css">
    body {
      background-color: white;
      font-family: sans-serif;
    }
    h1, h2, h3 {
      font-weight: normal;
    }
    </style>

    <script src="static/mobwrite/static/compressed_codemirror.js"></script>
    <script src="static/mobwrite/static/codemirror/js/codemirror.js"></script>
    <script>
      mobwrite.syncGateway = 'http://mobwrite3.appspot.com/scripts/q.py';
    </script>

  </head>
  <body onload="mobwrite.share(demo_editor_text);">

    <div id="content">
      <div id="save_form">
        <form class="lift:form.ajax" name="save_form">
          <lift:SaveBuffer filename="/tmp/the-buffer.txt">
    <textarea style="display:none" id="buffer" name="buffer"/>
      <!--
    <input type="hidden" id="buffer" name="buffer"/>
      -->
      <input type="hidden" id="filename" name="filename" value="/tmp/the-buffer.txt"/>
  </lift:SaveBuffer>
        </form>
      </div>

<script type="text/javascript">
  function saveBuffer() {
    var buffer = jQuery('#buffer')[0];
    buffer.value = demo_editor_text.getCode();
    var form = jQuery('#save_form form')[0];
    // this doesn't work!
    // form.submit();
    var onsubmit = form.getAttribute('onsubmit');
    var fs = 'function xyzzy() { ' + onsubmit + ' };';
    // alert('buffer ' + buffer.value);
    eval(fs);
    xyzzy();
  }
</script>

<table style="Width: 100%; height: 100%"> 
  <tr>
    <td style="height: 1%">
      <h1><lift:Menu.title/></h1>
    </td>
  </tr> 
  <tr>
    <td> 
      <div style="border: solid 1px black; height: 99%"> 
        <textarea id="usi_editor_text"></textarea> 
      </div> 
    </td>
  </tr> 
  <tr>
    <td> 
      <input type="button" value="Save" onclick="javascript:saveBuffer()"/>
    </td>
  </tr> 
</table> 
    </div>

    <script type="text/javascript">
      var demo_editor_text = mobwrite.shareCodeMirror.create(
        'usi_editor_text', {
          height: '100%',
          width: '100%',
          parserfile: ['tokenizejavascript.js', 'parsejavascript.js'],
          path: 'static/mobwrite/static/codemirror/js/',
          stylesheet: 'static/mobwrite/static/codemirror/css/jscolors.css',
          tabMode: 'shift',
          autoMatchParens: true
        });
    </script>

  <script type="text/javascript" src="/ajax_request/liftAjax.js"></script> 

  </body>
</html>
